package Logging;
import javax.swing.*;
import java.io.*;
public class LoggingManager implements IDebugLogger, IErrorLogger, IInfoLogger, IMessageBoxLogger, IWarningLogger {

	public void debugMsg(String message)
	{
		System.out.println("Debug: " + message);
		writeToFile("Debug: " + message);
	}
	public void errorMsg(String message)
	{
		System.err.println("Error: " + message);
		writeToFile("Error: " + message);
	}
	public void infoMsg(String message)
	{
		System.out.println("Info: " + message);
		writeToFile("Info: " + message);
	}
	public void messageBoxMsg(String message)
	{
		JOptionPane.showMessageDialog(null, message, "Message", JOptionPane.INFORMATION_MESSAGE);
		writeToFile("Message Box: " + message);
	}
	public void warnningMsg(String message)
	{
		System.out.println("Warning: " + message);
		writeToFile("Warning: " + message);
	}
	
	private void writeToFile(String message)
	{
		try 
		{
			File directory = new File("LogFiles");
			if(!directory.exists())
			{
				directory.mkdir();	
			}
			File f = new File("LogFiles\\log.txt");
			if(!f.exists())
			{
				f.createNewFile();	
			}
			BufferedWriter bw = new BufferedWriter(new FileWriter(f, true));
			bw.write(message);
			bw.newLine();
			bw.close();
		} 
		catch (IOException e) 
		{ 
			System.out.println("Exception");
		}
    
	}
}